package come.demo.widgets.ui;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import come.demo.widgets.BasePageAdapter;
import come.demo.widgets.BaseRecyclerAdapter;
import come.demo.widgets.R;

public class SpringbackActivity extends AppCompatActivity {
    public static void gotoActivity(Context context) {
        Intent intent = new Intent(context, SpringbackActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_springback);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        if (recyclerView != null) {
            recyclerView.setLayoutManager(new LinearLayoutManager(this));
            final List<String> list = new ArrayList<>();
            for (int i = 0; i < 100; ++i) {
                list.add(String.valueOf(i));
            }
            recyclerView.setAdapter(new SimpleAdapter(list));
        }
    }


    public static class SimpleAdapter extends BasePageAdapter<String, BaseRecyclerAdapter.BaseViewHolder> {

        public SimpleAdapter(List<String> data) {
            super(data);
        }


        @Override
        public BaseRecyclerAdapter.BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new BaseViewHolder(new TextView(parent.getContext()));
        }

        @Override
        public void onBindViewHolder(BaseRecyclerAdapter.BaseViewHolder holder, int position) {
            ((TextView) (holder.itemView)).setText(getItem(position));

            if (position == 0) {
                ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                marginLayoutParams.leftMargin = -10;
                holder.itemView.setLayoutParams(new RecyclerView.LayoutParams(marginLayoutParams));
            }
        }

    }
}
